package com.bradz.mymovies;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;

import java.io.File;
import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.net.URISyntaxException;
//import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
//import java.util.Arrays;
import java.util.List;
import java.util.TimerTask;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.vending.billing.IInAppBillingService;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.DialogInterface.OnClickListener;
import android.content.IntentSender.SendIntentException;
import android.content.res.Configuration;
import android.net.Uri;
//import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
//import android.view.MenuItem;
import android.view.View;
import android.view.Window;
//import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
//import android.widget.RatingBar;
//import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;

/*import org.apache.commons.io.comparator.LastModifiedFileComparator;
import org.apache.commons.io.comparator.NameFileComparator;
import org.apache.commons.io.comparator.PathFileComparator;
import org.apache.commons.io.comparator.SizeFileComparator;*/

/*
 * 
 * TODO:
 * 1) Make sure that there are control instructions that appear on the screen when the media player is loaded
 * 2) Add billing permissions to manifest and billing objects to store
 * 
 */
public class ActivityMain extends ListActivity {
        
    /** Called when the activity is first created. */
    private enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
    ClassSorterHelper sorty = new ClassSorterHelper();
    private final DISPLAYMODE displayMode = DISPLAYMODE.RELATIVE;
    private List<String> directoryEntries = new ArrayList<String>();
    private File rootDirectory = new File("/mnt/");
    private File currentDirectory = rootDirectory;
    public String path;
    //File selected;
    private Context self;
    private ListView fileList;
    private TextView someText;
    private ArrayAdapter<String> directoryList;
    
    private ServiceConnection mServiceConn;
    private IInAppBillingService mService;
    private ClassAndroidLogger logger;
    private Bundle buyIntentBundle;
    private ClassNetworkHelper helper;
    private ApplicationGlobalVars globals;
    //private DrawerLayout mDrawerLayout;
    //private ListView mDrawerList;
    //private ActionBarDrawerToggle mDrawerToggle;
    //private CharSequence mDrawerTitle;
    //private CharSequence mTitle;
    
    private String TAG = "myMovies";
    public boolean loading;

    /** Called when the activity is first created. */
    @SuppressLint("NewApi")
	@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.browser_screen);
        
        globals = ((ApplicationGlobalVars) this.getApplication());
	    helper = new ClassNetworkHelper(this,globals);
	    helper.log_into_network();
        
        fileList = (ListView) findViewById(android.R.id.list);
        someText = (TextView) findViewById(R.id.infoview);
        logger = new ClassAndroidLogger("MainActivity");
        loading = false;
        
        self = this;
        
        ((Button) findViewById(R.id.donate_button)).setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	sent_donation_purchase();
            }
        });
        
        bind_billing_activities();
        browseToRoot();
    }
   
    /**
     * This function browses to the
     * root-directory of the file-system.
     */
    private void browseToRoot() {
            browseTo(rootDirectory);
}
   
    /**
     * This function browses up one level
     * according to the field: currentDirectory
     */
    private void upOneLevel(){
            if(this.currentDirectory.getParent() != null)
                    this.browseTo(this.currentDirectory.getParentFile());
    }
   
    private void browseTo(final File aDirectory){
            final String path = aDirectory.getAbsolutePath().toLowerCase();
            //System.out.println(path);
                
            if (aDirectory.isDirectory()){
                    this.currentDirectory = aDirectory;
                    //System.out.println(aDirectory.listFiles());
                    fill(aDirectory.listFiles());
                    set_list_selected();
            }else{
                    OnClickListener okButtonListener = new OnClickListener(){
                            // @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                            if(    path.contains(".jpg") || path.contains(".png") 
                                || path.contains(".gif")){
                                Intent intent = new Intent();
                                intent.setAction(android.content.Intent.ACTION_VIEW);
                                intent.setDataAndType(Uri.fromFile(new File(aDirectory.getAbsolutePath())), "image/*");
                                startActivity(intent);
                            }
                            else if (  path.contains(".wmv") || path.contains(".mp4") 
                                        || path.contains(".avi") || path.contains(".divx")
                                        || path.contains(".fv4") || path.contains(".mov")
                                        || path.contains(".moov")|| path.contains(".mpeg4")
                                        || path.contains(".ogv") || path.contains(".xvid")
                                        || path.contains(".mpg") || path.contains(".mpeg")
                                        || path.contains(".mkv") || path.contains(".flv")
                                        || path.contains(".m4v")){
                                //This makes a custom video player because the default player is shit
                                Intent intent = new Intent(getBaseContext(), ActivityMediaPlayer.class);
                                intent.putExtra("PATH_ID", aDirectory.getAbsolutePath());
                                startActivity(intent);
                            }
                            else if (  path.contains(".ogg")|| path.contains(".mp3")
                                        || path.contains(".wav")|| path.contains(".flac")){
                                Intent intent = new Intent();
                                intent.setAction(android.content.Intent.ACTION_VIEW);
                                intent.setDataAndType(Uri.fromFile(new File(aDirectory.getAbsolutePath())), "audio/*");
                                startActivity(intent);
                            }else{
                            	//This makes a custom video player because the default player is shit
                            	Toast.makeText(self, "Invalid format found. Attempting to play as video media...", Toast.LENGTH_LONG).show();	
                            	
                                Intent intent = new Intent(getBaseContext(), ActivityMediaPlayer.class);
                                intent.putExtra("PATH_ID", aDirectory.getAbsolutePath());
                                startActivity(intent);
                                
                            }
                            }
                    };
                    OnClickListener cancelButtonListener = new OnClickListener(){
                            // @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                //Dismiss the alertdialog
                            	arg0.dismiss();
                            }
                    };
                    new AlertDialog.Builder(this)
                    .setTitle("Media Chosen")
                    .setMessage("Do you want to open this file?\n"+ aDirectory.getName())
                    .setPositiveButton("OK", okButtonListener)
                    .setNegativeButton("Cancel", cancelButtonListener)
                    .show();
            }
    }
    
    private void fill(File[] files){
    	sort_media(files);
    }
        
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if(this.currentDirectory.getParent() == null){
                    moveTaskToBack(true);
            }else{
                    this.upOneLevel();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
        
    protected void onListItemClick(ListView l, View v, int position, long id) {
            String selectedFileString = this.directoryEntries.get(position);
            //System.out.println(position);
            //System.out.println(selectedFileString);
            if (selectedFileString.equals(".")) {
                    // Refresh
                    this.browseTo(rootDirectory);
            } else if(selectedFileString.equals("..")){
                    this.upOneLevel();
            } else {
                    File clickedFile = null;
                    switch(this.displayMode){
                            case RELATIVE:
                                    clickedFile = new File(this.currentDirectory.getAbsolutePath()
                                                                                            + this.directoryEntries.get(position));
                                    break;
                            case ABSOLUTE:
                                    clickedFile = new File(this.directoryEntries.get(position));
                                    break;
                    }
                    //if(/*clickedFile != null && */(clickedFile.isDirectory() || clickedFile.equals(selected))){
                    this.browseTo(clickedFile);
                            //selected = null;
                    /*}*//*else{
                        selected = clickedFile;
                    }*/
            }
    }
    
    /* The click listner for ListView in the navigation drawer */
    /*private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        	Log.i("MyMovies","DrawerItemClickListener Position: " + position);  
            selectItem(position);
        }
    }*/

    /*@Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(mTitle);
    }*/
    
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        //if (savedInstanceState == null) {
        //    selectItem(0);
        //}
        // Sync the toggle state after onRestoreInstanceState has occurred.
        //mDrawerToggle.syncState();
    }
    
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        //mDrawerToggle.onConfigurationChanged(newConfig);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        SubMenu showMenu = menu.addSubMenu("Sort Media");
        menu.addSubMenu("Sync Mnt");
        ArrayList<String> sort_names = new ArrayList<String>();
        sort_names.add("Name");
        sort_names.add("Type");
        sort_names.add("Modified");
        sort_names.add("Size");
        for(int i = 0; i < sort_names.size();i++){
      	  showMenu.add(2,i, i, sort_names.get(i));
        }
        return super.onPrepareOptionsMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
         // The action bar home/up action should open or close the drawer.
         // ActionBarDrawerToggle will take care of this.
    	
    	Log.i("MyMovies","onOptionsItemSelected Position: " + item.getItemId());  
    	int itemId = item.getItemId();
    	if(item.getTitle() == "Sync Mnt"){
    		logger.info("Syncing with server!");
    		Sync_Media async_sync = new Sync_Media();
    		async_sync.execute();
    		return true;
    	}
    	else if (!item.hasSubMenu()){
      	  Log.i("myMovies","Doesn't have submenu. Selecting...");
      	  sorty.setSorter(itemId);
      	  browseTo(currentDirectory);
      	  return true;
        }
        return false;
    }
    
    private void sort_media(File[] files){
    	Sort_Media async_sort = new Sort_Media(this,(FrameLayout) findViewById(R.id.loading_frame),files);
    	if(!loading){
    		loading = true;
    		async_sort.execute();
    	}
    }
    
    //private void selectItem(int position) {
    	
    //	Log.i(TAG,"Position: " + position);    	
    	
    //	sorty.setSorter(position);
    	//sort_media(position);
    	
    //    browseTo(currentDirectory);
        //mDrawerList.setItemChecked(position, true);
        //mDrawerLayout.closeDrawer(mDrawerList);
    //}
    
    public class Sort_Media extends AsyncTask<Void, Void, Void>
    {
    	private FrameLayout loading_frame;
    	private File[] files;
    	private Context context;
    	private List<String> newDirectoryEntries = new ArrayList<String>();
    	
		Sort_Media(Context context, FrameLayout loading_frame, File[] files){
			this.context = context;
			this.loading_frame = loading_frame;
			this.files = files;
		}
		
        @Override
        protected void onPreExecute()
        {
        		loading_frame.setVisibility(View.VISIBLE);
        		newDirectoryEntries.clear();
        }

        @Override
        protected Void doInBackground(Void... params)
        {
        	//final File sortDirectory = currentDirectory;
           
            // Add the "." and the ".." == 'Up one level'
            try {
                    Thread.sleep(10);
            } catch (InterruptedException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
            }
            newDirectoryEntries.add(".");
           
            if(currentDirectory.getParent() != null){
            	newDirectoryEntries.add("..");
            }
           
            files = sorty.fileSort(files);
            
            switch(displayMode){
                    case ABSOLUTE:
                        if(files != null){
                        for (File file : files){
                                if(file!=null){
                                	newDirectoryEntries.add(file.getPath());
                                }
                        }
                        }
                        break;
                    case RELATIVE: // On relative Mode, we have to add the current-path to the beginning
	                    int currentPathStringLength = currentDirectory.getAbsolutePath().length();
	                    if(files != null){
	                    for (File file : files){
	                        if(file!=null){
	                        	newDirectoryEntries.add(file.getAbsolutePath().substring(currentPathStringLength));
	                        }
	                    }
	                    }
	                    break;
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
        	directoryEntries = new ArrayList<String>(newDirectoryEntries);
            directoryList = new ArrayAdapter<String>(context,R.layout.file_row, directoryEntries);
            someText.setText("Location: \n" + currentDirectory.getAbsolutePath());
            path = currentDirectory.getAbsolutePath();
            fileList.setAdapter(directoryList);
            directoryList.notifyDataSetChanged();
        	loading_frame.setVisibility(View.INVISIBLE);
        	set_list_selected();
        	loading = false;
        }

    }
    
    public class Sync_Media extends AsyncTask<Void, Void, Void>
    {
    	List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    	JSONObject data = new JSONObject();
    	
    	private File rootDirectory = new File("/mnt/");
    	private JSONArray json_array = new JSONArray();
    	
    	class Media_Storage{
    		String parent;
    		String file;
    		Media_Storage(String parent, String file){
    			this.file = file;
    			this.parent = parent;
    		}
    	}
    	
    	private String return_show_path(String show_path){
    		return show_path.substring(show_path.lastIndexOf('/')==-1?0:show_path.lastIndexOf("/")+1,show_path.length());
    	}
    	
    	private String list_to_string(List<String> string_list){
    		String list_string = "[";
    		for(String item: string_list){
    			list_string += "\""+ item + "\",";
    		}
    		list_string += "]";
    		return list_string;
    	}
    	
    	private void recurse_path(File folder){
    		try{
    			String parent = folder.getAbsolutePath();
    			List<String> files = new ArrayList<String>();
	    		for(File file:folder.listFiles()){
	        		if(file.isDirectory()){
	        			recurse_path(file);
	        		}else{
	        			files.add(return_show_path(file.getCanonicalPath()));
	        		}
	        		logger.info(file.getAbsolutePath());
	        	}
	    		data.put(parent, list_to_string(files));
	    	} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    		
    	}
    	
    	Sync_Media(){}
		
        @Override
        protected void onPreExecute()
        {

        }

        @Override
        protected Void doInBackground(Void... params)
        {
        	recurse_path(rootDirectory);
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
        	logger.info("Finished Sync. Sending Data To Server!");
        	logger.info(data.toString().replace("\"", ""));
        	
        	List<NameValuePair> pairs = new ArrayList<NameValuePair>();
			pairs.add(new BasicNameValuePair("data", data.toString()));
    		pairs.add(new BasicNameValuePair("type", "media"));
        	
        	helper.send_message(pairs,"set_media/");
        }

        
    }
    
    public void set_list_selected(){
    	((FrameLayout) findViewById(R.id.content_frame)).requestFocus();
        fileList.setSelected(true);
        fileList.setSelection(0);
    }
    
    public void bind_billing_activities(){
		mServiceConn = new ServiceConnection() {
			   @Override
			   public void onServiceDisconnected(ComponentName name) {
				   Log.i(TAG,"Billing Service Disconnected..."); 
				   mService = null;
			   }

			   @Override
			   public void onServiceConnected(ComponentName name, IBinder service) {
				   Log.i(TAG,"Billing Service Connected..."); 
				   mService = IInAppBillingService.Stub.asInterface(service);
			   }
		};
		bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
	}
    
    public void sent_donation_purchase(){
		ClassDeveloperPayload payload = new ClassDeveloperPayload();
    	
    	LoadBillingTask task = new LoadBillingTask(payload.get_payload(), "mymovies_donation");
    	
    	task.run();
	}
    
    class LoadBillingTask extends TimerTask {
        private Handler mHandler = new Handler(Looper.getMainLooper());
		String payload;
		String item_name;

        LoadBillingTask(String payload, String item_name){
        	logger.info("Init Billing");
  			this.payload = payload;
  			this.item_name = item_name;
  			logger.info("Done Init Billing");
        }
        
        @Override
        public void run() {
           mHandler.post(new Runnable() {
              public void run() {
            	  try {
            		  logger.info("Starting runnable");
            		  logger.info("package: " + getPackageName());
            		  logger.info("item: " + item_name);
            		  logger.info("payload: " + payload);
            		if(mService == null){
            			logger.info("mService: invalid");
            			logger.toast("There was a problem connecting to the billing service", self);
            		}else{
            			logger.info("mService: valid");
            			buyIntentBundle = mService.getBuyIntent(3, getPackageName(), item_name, "inapp", payload);
            			logger.info("Intent info");
            			if(buyIntentBundle.getInt("RESPONSE_CODE") != 7){
	            			logger.info("Starting pending intent");
	            			
	          				PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
	          				
	          				logger.info("Starting sender for result");
	          				startIntentSenderForResult(pendingIntent.getIntentSender(),
	          					   1641, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
	          					   Integer.valueOf(0));
            			}else{
            				logger.toast("This product has already been purchased!", self);
            			}
            		}
      			} catch (RemoteException e) {
      				logger.error(e.toString());
      				e.printStackTrace();
      			} catch (SendIntentException e) {
      				logger.error(e.toString());
      				e.printStackTrace();
      			} catch (Exception e){
      				logger.error(e.toString());
      				e.printStackTrace();
      			}
              }
           });
         }
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)    
    {
        super.onActivityResult(requestCode, resultCode, data);
        logger.info("RequestCode: " + requestCode);
        logger.info("ResultCode: " + resultCode);
        if (requestCode == 1641 && resultCode == Activity.RESULT_OK) {           
        	logger.info("onactivity result called inside request code");
            try{
            	
            	logger.info("Parsing response data");
	            int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
	            logger.info("ResponseCode: " + responseCode);
	            String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
	            logger.info("purchaseData: " + purchaseData);
	            String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
	            logger.info("dataSignature: " + dataSignature);
	            
	            
	            if (responseCode == Constants.BILLING_RESPONSE_RESULT_OK) {
	                try {
    	                JSONObject jo = new JSONObject(purchaseData);
    	                String sku = jo.getString("productId");
    	                logger.info("productId: " + sku);
    	                //This is where the purchase needs to actually be put into the system...
    	                
    	                JSONObject o = new JSONObject(purchaseData);
    	                logger.info("Purchase Data: " + o.toString());
    	                String mOrderId = o.optString("orderId");
    	                logger.info("mOrderId: " + mOrderId);
    	                String mPackageName = o.optString("packageName");
    	                logger.info("mPackageName: " + mPackageName);
    	                String mSku = o.optString("productId");
    	                logger.info("mSku: " + mSku);
    	                long mPurchaseTime = o.optLong("purchaseTime");
    	                logger.info("purchaseTime: " + mPurchaseTime);
    	                int mPurchaseState = o.optInt("purchaseState");
    	                logger.info("mPurchaseState: " + mPurchaseState);
    	                String mDeveloperPayload = o.optString("developerPayload");
    	                logger.info("mDeveloperPayload: " + mDeveloperPayload);
    	                String mToken = o.optString("token", o.optString("purchaseToken"));
    	                logger.info("mToken: " + mToken);
    	                
    	                //Need to consume the purchase before returning
    	                try {
    	                    mService.consumePurchase(3, getPackageName(), mToken);
    	                } catch (RemoteException e) {
    	                	logger.error(e.toString());
    	                    e.printStackTrace();
    	                }
    	                
    	                //This is the method that reflects back to the prototype
                		Object[] parameterTypes = new Object[2];
                        parameterTypes[0] = Integer.valueOf(o.optString("developerPayload").split(">>>")[0]);
                        parameterTypes[1] = mToken;
                		
    					try {
	    	                logger.toast("Thank you for your donation! Now we can afford to eat tonight!", self);
    						
    					} catch (IllegalArgumentException e) {
    						// TODO Auto-generated catch block
    						logger.error(e.toString());
    						e.printStackTrace();
    					} 
	                }catch (JSONException e) {
	                            Toast.makeText(this, "Failed to parse purchase data.", Toast.LENGTH_SHORT);
	                            logger.error(e.toString());
	                            e.printStackTrace();
	                }
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_USER_CANCELED) {
	                	logger.error("User cancelled purchase"); 
	                	Toast.makeText(this, "User cancelled purchase.", Toast.LENGTH_SHORT).show();
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE) {
	                	logger.error("Your Device doesn't support inapp billing"); 
	                	Toast.makeText(this, "Your Device doesn't support inapp billing.", Toast.LENGTH_SHORT).show();
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE) {
	                	logger.error("Item is not available for billing"); 
	                	Toast.makeText(this, "Item is not available for billing", Toast.LENGTH_SHORT).show();
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_DEVELOPER_ERROR) {
	                	logger.error("Can't purchase item due to some developer error"); 
	                	Toast.makeText(this, "Can't purchase item due to some developer error.", Toast.LENGTH_SHORT).show();
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ERROR) {
	                	logger.error("Can't purchase item due to some error in response"); 
	                	Toast.makeText(this, "Can't purchase item due to some error in response.", Toast.LENGTH_SHORT).show();
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
	                	logger.error("You already own this item"); 
	                	Toast.makeText(this, "You already own this item.", Toast.LENGTH_SHORT).show();
	                }else if (responseCode == Constants.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) {
	                	logger.error("You don't own this item");
	                    Toast.makeText(this, "You don't own this item.", Toast.LENGTH_SHORT).show();
	                }
            }catch(Exception e){
            	logger.error(e.toString());
            	logger.error("Unable to make purchase");
            	Toast.makeText(this, "Unable to make purchase.", Toast.LENGTH_SHORT).show();
            }
        }
        
    }
    
    public class Constants{
    	static final int BILLING_RESPONSE_RESULT_OK	= 0;
    	static final int BILLING_RESPONSE_RESULT_USER_CANCELED = 1;
    	static final int BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE = 3;
    	static final int BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE	= 4;
    	static final int BILLING_RESPONSE_RESULT_DEVELOPER_ERROR = 5;
    	static final int BILLING_RESPONSE_RESULT_ERROR = 6;
    	static final int BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED = 7;
    	static final int BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED = 8;
    }
    
}